package cl.fbd.widget_examples.web.snippet

import scala.xml.{NodeSeq, Node, PCData, Text, Unparsed}

import net.liftweb.widgets.trees.model._
import net.liftweb.widgets.trees.treeview._
import cl.fbd.widget_examples.web.model.{TimeSerieMeasureModel, TimeSerie, Measure}

import net.liftweb.util.Helpers._

/*
 * render a treeview
 */

class TreeView {
  val sdf = new java.text.SimpleDateFormat ("dd/MM/yyyy")
  
  def renderMeasure (xhtml: NodeSeq, measure : Measure) = {
    bind ("medicion", xhtml, "mm" --> measure.value, 
                             "fecha" --> sdf.format (measure.when))
  }

  def renderTimeSerie (xhtml: NodeSeq, timeserie : TimeSerie) = {
    bind ("timeserie", xhtml, "nombre" --> (timeserie.what + " / " + timeserie.where),  
                             "sum" --> timeserie.sum)
  }

  
  def render (xhtml: NodeSeq) = {
    val model = TimeSerieMeasureModel.initModel
    
    val tvOptions = new TreeViewOptions ()
    
    bind ("treeview", xhtml,  
          "renderXyz" --> TreeView.render ("xyz", tvOptions),
          "renderAbc" --> TreeView.render (model, tvOptions, renderMeasure, renderTimeSerie) 
        )
  }
}

